<?php

namespace app\controller\web;

use app\service\HelpProblemInfoService;
use app\validate\HelpProblemInfoValidate;
use app\validate\PageValidate;
use share\utils\Helper;

class HelpProblemInfoController extends WebBaseController{

    public function initValidate(){        
        $this->validate = new HelpProblemInfoValidate();
    }

    /**
     * 新增项目信息
     */
    public function add_action(){
        $input = $this->check();
        $data = HelpProblemInfoService::addHelp($input);
        return self::ok($data);
    }

    /**
     * 修改项目信息
     */
    public function edit_action(){
        $input = $this->check();
        $data = HelpProblemInfoService::updateHelp($input);
        return self::ok($data);
    }

    /**
     * 删除项目信息
     */
    public function del_action(){
        $input = $this->check();
        $data = HelpProblemInfoService::delHelp($input['id']);
        return self::ok($data);
    }

    /**
     * 列表 搜索
     */
    public function list_action(){        
        $page = $this->check('pageInfo',null,(new PageValidate()));
        $input = [];       
        $data = HelpProblemInfoService::getListInfo($input,$page);
        $data = Helper::arrayListReplaceKey($data,[
            'first_time' => 'firstTime',
            'modify_time' => 'modifyTime',
        ]);
        $total = HelpProblemInfoService::getListCountInfo($input);
        return self::ok(self::formatPageData($page,$total,$data));
    }

    /**
     * 问题类型
     */
    public function type_list_action(){
        return self::ok(HelpProblemInfoService::typeNameList());
    }
}